package com.mashibing.controller;

import com.mashibing.internalcommon.dto.OrderInfo;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.OrderRequest;
import com.mashibing.request.ApiPassengerOrderRequest;
import com.mashibing.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    public ResponseResult addOrder(@Validated @RequestBody ApiPassengerOrderRequest orderRequest) {
        return orderService.addOrder(orderRequest);
    }

    /**
     * 乘客取消订单
     * @param orderId
     * @return
     */
    @PostMapping("/cancel")
    public ResponseResult cancel(@RequestParam Long orderId){
        return orderService.cancel(orderId);
    }

    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(@Validated @NotNull(message = "订单id不能为空") @Positive(message = "订单id格式不正确") Long orderId){
        return orderService.detail(orderId);
    }

    @PostMapping("/book")
    public ResponseResult book(@Validated @RequestBody ApiPassengerOrderRequest orderRequest) {
        return orderService.book(orderRequest);
    }
}
